<?php


namespace App\Transformers\Store;


use App\Models\StoreCombination;
use App\Transformers\Product\ProductAttrTransformer;
use App\Transformers\Product\ProductTransformer;
use League\Fractal\TransformerAbstract;

class StoreCombinationTransformer extends TransformerAbstract
{
    protected $availableIncludes = ['product','merchantRegister'];

    public function transform(StoreCombination $data)
    {
        return [
            'id' => $data->id,
            'product_id' => $data->product_id ?? "",
            'merchant_id' => $data->merchant_id ?? "",
            'recommend_image' => $data->recommend_image ?? "",
            'recommend_image_url' => $data->recommend_image ?? 'https://placeimg.com/640/480/any',
            'rotation_chart' => $data->rotation_chart ?? "",
            'rotation_chart_url' => $data->rotation_chart ?? 'https://placeimg.com/640/480/any',
            'title' => $data->title ?? "",
            'attribute' => $data->attribute ?? "",
            'people' => $data->people ?? "",
            'introduce' => $data->introduce ?? "",
            'price' => $data->price ?? "",
            'sort' => $data->sort ?? "",
            'sales' => $data->sales ?? "",
            'stock' => $data->stock ?? "",
            'postage' => $data->postage ?? "",
            'start_at' => $data->start_at ?? "",
            'stop_at' => $data->stop_at ?? "",
            'order_effective_at' => $data->order_effective_at ?? "",
            'goods_cost' => $data->goods_cost ?? "",
            'browse' => $data->browse ?? "",
            'unit_name' => $data->unit_name ?? "",
            'temp_id' => $data->temp_id ?? "",
            'weight' => $data->weight ?? "",
            'volume' => $data->volume ?? "",
            'num' => $data->num ?? "",
            'once_num' => $data->once_num ?? "",
            'quota' => $data->quota ?? "",
            'quota_show' => $data->quota_show ?? "",
            'virtual' => $data->virtual ?? "",
            'is_recommend' => $data->is_recommend ?? 0,
            'status' => $data->status ?? 0,
            'active_status' => $data->activeStatusEnum[$data->active_status]?? "",
            'merchant_use' => $data->merchant_use ?? 0,
            'is_postage' => $data->is_postage ?? 0,
            'description' => $data->description ?? 0,
            'deleted_at' => $data->deleted_at ? $data->deleted_at->format("Y-m-d H:i:s") : '',
            'created_at' => $data->created_at ? $data->created_at->format("Y-m-d H:i:s") : '',
            'updated_at' => $data->updated_at ? $data->updated_at->format("Y-m-d H:i:s") : '',
            'att_r' => $data->att_r ?? '',
        ];
    }

    /**
     *额外包含商品数据
     */

    public function includeProduct(StoreCombination $storeCombination)
    {
        return $this->item($storeCombination->product, new ProductTransformer());
    }

    /**
     *额外包含商户信息
     */

    public function includeMerchantRegister(StoreCombination $storeCombination)
    {
        return $this->item($storeCombination->merchantRegister, new MerchantRegistersTransformer());
    }

}
